package com.akcome.apollo.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.akcome.apollo.domain.BmpIncome;

/**
 * 收益记录Repository接口
 *
 * @author wn
 * @version $v: 1.0.0, $time:2017-12-26 08:49:00 Exp $
 */
public interface BmpIncomeRepository extends JpaRepository<BmpIncome,Long>,JpaSpecificationExecutor<BmpIncome> {

	@Query(nativeQuery=true,value="select ifnull(sum(amount),0) from bmp_income where account_id=?1 and coin_type=?2 and status!='03'")
	Double sumEarn(Long accountId,String coinType);
	
	@Query(nativeQuery=true,value="select ifnull(sum(amount),0) from bmp_income where account_id=?1 and coin_type=?2")
	Double totalIncome(Long accountId,String coinType);
	
	@Query(nativeQuery=true,value="select ifnull(sum(amount),0) from bmp_income where account_id=?1 and coin_type=?2 and DATE_FORMAT(pay_time,'%Y-%m-%d')=?3")
	Double sumAmountByAccountIdAndCoinTypeAndDate(Long accountId,String coinType,String date);
	
	int countByAccountId(Long accountId);
}
